var t = require("../../../@babel/runtime/helpers/interopRequireDefault").default,
  a = require("../../../utils/http"),
  e = t(require("../../../utils/util")),
  n = new a.HTTP;
let { contacts, contactss,linkman } = require("../../../api/attract/select");
let citys=require("../../../utils/citys2")

Page({
  data: {
    fieldNames: {
      text: 'label',
      value: 'label',
      children: 'children',
    },
    show: false,
    options:citys.citys,
    fieldValue: '',
    cascaderValue: '',
    qymclxr:'',
    region: ["", "", ""],

    lxrxlList:[{text:'暂无',id:'暂无'},{text:'高中及以下',id:'高中及以下'},{text:'大专',id:'大专'},{text:'本科',id:'本科'},{text:'硕士',id:'硕士'},{text:'博士',id:'博士'}],
    lxrxl:'暂无',
    selectArray: [{
      id: 1,
      text: "初相识"
    }, {
      id: 2,
      text: "一般关系"
    }, {
      id: 3,
      text: "朋友关系"
    }, {
      id: 4,
      text: "好友关系"
    }],
    lianxiren: [{
      id: 1,
      text: "否"
    }, {
      id: 2,
      text: "是"
    }],
    lianxi: 1,
    lianxis: "否",
    sortType: 1,
    nowText: "初相识"
  },
  onClick() {
    this.setData({
      show: true,
    });
  },

  onClose() {
    this.setData({
      show: false,
    });
  },

  onFinish(e) {
    console.log(e.detail)
    const { selectedOptions, value } = e.detail;
    const fieldValue = `${selectedOptions[0].label}/${selectedOptions[1].label}`;
    this.setData({
      fieldValue,
      cascaderValue: value,
      'region[0]':selectedOptions[0].label,
      'region[1]':selectedOptions[1].label,
      // 'region[2]':selectedOptions[2].label,
    })
    console.log(this.data.region)
    this.onClose()
  },
  bindRegionChange: function (e) {
    console.log("picker发送选择改变，携带值为", e.detail.value);
    this.setData({
      region: e.detail.value,
    });
  },
  selectEvent: function (t) {
    this.setData({
      sortType: t.detail.selectedID,
      nowText: t.detail.nowText
    })
  },
  lianxiEvent: function (t) {
    this.setData({
      lianxi: t.detail.selectedID,
      lianxis: t.detail.nowText
    })
  },
  lxrxlEvent: function (t) {
    this.setData({
      lxrxl: t.detail.selectedID,
      lxrxl: t.detail.nowText
    })
  },
  formSubmit: function (t) {
    var a = this,
      e = t.detail.value;
    wx.showModal({
      title: "提示",
      content: "请核对数据是否准确",
      success: function (t) {
        t.confirm && (e.lxr && e.iphonenum&&a.data.region[0]&&a.data.region[1] ? null == a.data.cunzai ? (contactss({
          qymc: a.data.infor.qymc,
          lxr: e.lxr,
          zw: e.zw,
          lxphone: e.iphonenum,
          yx: e.yx,
          qq: e.qq,
          wxh: e.wxh,
          qmcd: a.data.nowText,
          grah: e.grah,
          sylxr: a.data.lianxis=='是'?2:1,

          tname: a.data.tname,
          tjsj: a.data.yjdc,
          lxrxl:a.data.lxrxl,
          lxrjga:a.data.region[0],
          lxrjgb:a.data.region[1],
          // lxrjgc:a.data.region[2],
                khbh: a.data.infor.khbh,
                lxryx: e.lxryx,
        }).then((function (t) {
          wx.showToast({
              title: "添加成功",
              icon: "success",
              duration: 1e3
            }),
            n.request({
              url: "https://www.qlsyyun.com:3000/addlink/stjd",
              header: {
                "Content-Type": "application/x-www-form-urlencoded"
              },
              method: "POST",
              data: {
                qymc: a.data.infor.qymc,
                bm: a.data.bm,
                zsy: a.data.tname,
                xm: e.lxr,
                tjsj: a.data.yjdc,
                khbh: a.data.infor.khbh
              }
            }).then((function (t) {})),
            n.request({
              url: "https://www.qlsyyun.com:3000/contacts/stmx",
              header: {
                "Content-Type": "application/x-www-form-urlencoded"
              },
              method: "POST",
              data: {
                qymc: a.data.infor.qymc,
                tjsj: a.data.yjdc,
                zsy: a.data.tname,
                xm: e.lxr
              }
            }).then((function (t) {
              let pages = getCurrentPages()
              let beforePage = pages[pages.length - 2];
              // 假设main()为页面A的数据方法，
              beforePage.onLoad({
                bID: a.data.infor.bID,
                id: 1,
                qdid:a.data.infor.bID
              });
              wx.navigateBack({
                delta: 1,
              });
            }))
        }))) : contacts( {
          lID: a.data.lID,
          lxr: e.lxr,
          zw: e.zw,
          lxphone: e.iphonenum,
          yx: e.yx,
          qq: e.qq,
          wxh: e.wxh,
          qmcd: a.data.nowText,
          grah: e.grah,
          sylxr: a.data.lianxis=='是'?2:1,
          tname: a.data.tname,
          tjsj: a.data.yjdc,
          lxrxl:a.data.lxrxl,
          lxrjga:a.data.region[0],
          lxrjgb:a.data.region[1],
          // lxrjgc:a.data.region[2],
                khbh: a.data.infor.khbh,
                lxryx: e.lxryx,
        }).then((function (t) {
          wx.showToast({
              title: "添加成功",
              icon: "success",
              duration: 1e3
            }),
            
            n.request({
              url: "https://www.qlsyyun.com:3000/addlink/stjd",
              header: {
                "Content-Type": "application/x-www-form-urlencoded"
              },
              method: "POST",
              data: {
                qymc: a.data.infor.qymc,
                bm: a.data.bm,
                zsy: a.data.tname,
                xm: e.lxr,
                tjsj: a.data.yjdc,
                khbh: a.data.infor.khbh
              }
            }).then((function (t) {})),
            n.request({
              url: "https://www.qlsyyun.com:3000/contacts/stmx",
              header: {
                "Content-Type": "application/x-www-form-urlencoded"
              },
              method: "POST",
              data: {
                qymc: a.data.infor.qymc,
                tjsj: a.data.yjdc,
                zsy: a.data.tname,
                xm: e.lxr
              }
            }).then((function (t) {}))
            let pages = getCurrentPages()
          let beforePage = pages[pages.length - 2];
          // 假设main()为页面A的数据方法，
          beforePage.onLoad({
            bID: a.data.infor.bID,
            id: 1,
            qdid:a.data.infor.bID

          });
          wx.navigateBack({
            delta: 1,
          });
           
        })) : wx.showToast({
          title: "请填写必填信息",
          icon: "none",
          duration: 1e3
        }))
      }
    })
  },
  onLoad: function (t) {
    var a = this;
    a.setData({
      lID: t.lID
    });
    a.setData({
      qymclxr:wx.getStorageSync("qymclxr")
    })
    var o = wx.getStorageSync("infor"),
      i = wx.getStorageSync("user"),
      d = e.default.formatnow(new Date);
    a.setData({
        yjdc: d,
        tname: i[0],
        bm: i[1],
        infor: o
      }),
      linkman(t.lID).then((function (t) {
        a.setData({
          gengxin: t.data[0],
          "region[0]": t.data[0].lxrjga ? t.data[0].lxrjga : "",
      "region[1]": t.data[0].lxrjgb ? t.data[0].lxrjgb : "",
      // "region[2]": t.data[0].lxrjgc ? t.data[0].lxrjgc : "",
      fieldValue:t.data[0].lxrjga ?`${t.data[0].lxrjga}/${t.data[0].lxrjgb}`:'',
      cascaderValue:t.data[0].lxrjgb ?t.data[0].lxrjgb:'',
        })
      }))
  },
  quxiao: function () {
    wx.navigateBack({
      delta: 1
    })
  },
  onShow: function () {
    var t = this;
    n.request({
      url: "https://www.qlsyyun.com:3000/contactsqymc",
      data: {
        lID: t.data.lID
      }
    }).then((function (a) {
      t.setData({
        cunzai: a.data[0]
      })
    }))
  }
});